<?php 	namespace Common\Model;
use Hdphp\Model\Model;
class User extends Model
{
	//操作数据表
	protected $table = "manager";
	//自动验证，必须通过create方法来触发
	protected $validate = array(
	//1.name名称;2.验证规则;3.提示信息;4.验证条件5.验证时间
	array("username","required","请输入用户名",3,3),
	array("password","required","请输入用户名",3,3),
	);
	/*
	 * 登录
	 * */
	 public function login()
	 {
	 	//自动验证
	 	if(!$this->create()) return false;
		//接收post数据
		$username = $_POST['username'];
		$password = md5($_POST['password']);
		//验证用户名
		$data = $this->where('username',$username)->first();
//		p($data);die;
		if(!$data)
		{
			//用户名不存在
			//存入到属性中，可以被getError()方法接收到
			$this->error = "用户名不存在";
			return false;
		}
		//验证密码
		if($data['password'] != $password)
		{
			//把错误信息存在error属性
			$this->error = "密码错误";
			return false;
		}
		//走到这里，说明用户名和密码正确
		$_SESSION['oid'] = $data['oid'];
		$_SESSION['username'] = $username;
		return true;
	 }
}
